Button Customization

Override the Delete Button Handler

Description
This customization shows how to handle OnClick event for Delete button in a page.
Variables
Table Control
Select the table control displaying the records you want to delete
Table Name
Select the database table to which the table control is bound
Field Value Control
Select the field value control on which you want to perform check
Button Control
Select the delete button
Applies to
P_Button Control class
Code
 
 // 
 // Override the DeleteButton_Click() button handler method. Add custom logic that gets executed
 // on ${Button Control}_Click
 // 
 public override void ${Button Control}_Click(object sender, ImageClickEventArgs args)
 {
     
      try 
	  {
           DbUtils.StartTransaction();
           ${Table Control}Row[] reclist = this.GetSelectedRecordControls();
     
		// Loop through each selected record
           foreach (${Table Control}Row rec in reclist)
           {
				// If the field contains value "11111", then the deletion of the record is cancelled and an error message is displayed; otherwise, the 
				// selected record is deleted   	
				if (rec.${Field Value Control}.Text.Equals("11111"))
				{
                    BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "Cannot delete record", "Cannot delete record with ${Field Value Control} = " + rec.${Field Value Control}.Text);
					
					//Set the selection of the record to false so that the deletion of the record does not takes place.
					rec.${Table Name}RecordRowSelection.Checked = false;
					
				}
           }
		   
           this.DeleteSelectedRecords(false);
           this.Page.CommitTransaction(sender);
	   }catch (Exception ex) {   
				BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "BUTTON_CLICK_MESSAGE", ex.Message);
		        this.Page.RollBackTransaction(sender);
       } finally {
          DbUtils.EndTransaction();
       }
     
    
 }

 

Terms of Service Privacy Statement